package com.itheima.test;

import lombok.Data;

public class JobTest2 {
    public static void main(String[] args) {
        Student student = new Student();
        try {
            studentSetSex(student);
        } catch (SexInputException a) {
            a.printStackTrace();
        }
        try {
            studentSetAge(student);
        } catch (AgeInputException a) {
            System.out.println("年龄错误");
            a.printStackTrace();
        }
    }

    static void studentSetSex(Student student) {

        student.setSex("sss");
        if (student.getSex().equals("男") || student.getSex().equals("女")) {
            System.out.println("性别正确");
        } else {
            throw new SexInputException("性别异常");
        }
    }

    static void studentSetAge(Student student) {
        student.setAge(100);
        if (student.getAge() > 0 && student.getAge() < 100) {
            System.out.println("年龄正常");
        } else {
            throw new AgeInputException("年龄异常");
        }
    }
}

class SexInputException extends RuntimeException {
    public SexInputException(String message) {
        super(message);
    }

    public SexInputException() {
    }
}

class AgeInputException extends RuntimeException {
    public AgeInputException() {
    }

    public AgeInputException(String message) {
        super(message);
    }
}

@Data
class Student {
    private String name;
    private String sex;
    private int age;

    public Student() {
    }

    public Student(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    @Override
    public String toString() {
        return name + ", " + sex + ", " + age;
    }
}


